package com.chenfan.infra.context;

import com.chenfan.infra.vo.UserVO;

/**
 * 获取用户上下文
 * @author K
 * @date 2022-04-21
 */
public class UserContextHolder {
    private static final InheritableThreadLocal<UserVO> USER_CONTEXT_HOLDER = new InheritableThreadLocal<>();
    private static final InheritableThreadLocal<String> TOKEN_CONTEXT_HOLDER = new InheritableThreadLocal<>();

    private UserContextHolder() {}

    public static UserVO getUserVo() {
        return USER_CONTEXT_HOLDER.get();
    }

    public static void setUserVo(UserVO userVo) {
        USER_CONTEXT_HOLDER.set(userVo);
    }

    public static void setToken(String token) {
        TOKEN_CONTEXT_HOLDER.set(token);
    }

    public static String getToken() {
        return TOKEN_CONTEXT_HOLDER.get();
    }

    public static void remove() {
        USER_CONTEXT_HOLDER.remove();
        TOKEN_CONTEXT_HOLDER.remove();
    }
}